package com.zengdada.authority.utils.excel.export.style;

import com.zengdada.authority.utils.CommonUtils;
import org.apache.poi.ss.usermodel.*;

/**
 * @author 12614
 * @contact 1261438511@qq.com
 * @date 2020-05-26 23:21
 * @describe 仅仅作为保存样式配置的 实体类 让它能够在构造文档前可以被初始化和定义
 */
public class MyCellStyle {

    private FillPatternType fillPattern;
    private Short fillBackgroundColor;
    private Short fillForegroundColor;
    private HorizontalAlignment alignment;
    private VerticalAlignment verticalAlignment;
    private BorderStyle borderLeft;
    private BorderStyle borderRight;
    private BorderStyle borderTop;
    private BorderStyle borderBottom;
    private Short leftBorderColor;
    private Short rightBorderColor;
    private Short topBorderColor;
    private Short bottomBorderColor;
    private Short dataFormat;
    private Short rotation;
    private MyFont font;
    private Short indention;
    private Boolean hidden;
    private Boolean locked;
    private Boolean wrapText;


    public MyCellStyle() {
    }

    public MyCellStyle(MyCellStyle cellStyle) {
        merge(cellStyle);
    }

    public MyCellStyle(CellStyle cellStyle, Font font) {
        this(cellStyle);
        if (font != null) {
            setFont(new MyFont(font));
        }
    }

    public MyCellStyle(CellStyle cellStyle) {
//        this.fillPattern = cellStyle.getFillPattern();
//        this.fillBackgroundColor = cellStyle.getFillBackgroundColor();
//        this.fillForegroundColor = cellStyle.getFillForegroundColor();
//        copyObjectNotNullAttribute(cellStyle, this, true);
        CommonUtils.copyObjectNotNullAttributeByGetMethod(cellStyle, this, true);
    }

    public MyCellStyle merge(MyCellStyle cellStyle) {
//        if (cellStyle.fillPattern != null && !cellStyle.fillPattern.equals(this.fillPattern))
//            this.fillPattern = cellStyle.fillPattern;
//        if (cellStyle.fillBackgroundColor != -1)
//            this.fillBackgroundColor = cellStyle.fillBackgroundColor;
//        if (cellStyle.fillForegroundColor != -1)
//            this.fillForegroundColor = cellStyle.fillForegroundColor;
        CommonUtils.copyObjectNotNullAttribute(cellStyle, this, true);
        return this;
    }

    public CellStyle initCellStyle(CellStyle cellStyle) {
//        if (this.fillPattern != null)
//            cellStyle.setFillPattern(this.fillPattern);
//        if (this.fillBackgroundColor != -1)
//            cellStyle.setFillBackgroundColor(this.fillBackgroundColor);
//        if (this.fillForegroundColor != -1)
//            cellStyle.setFillForegroundColor(this.fillBackgroundColor);

        CommonUtils.copyObjectNotNullAttribute(this, cellStyle, true);
        return cellStyle;
    }

    @Override
    public boolean equals(Object obj) {

        if (!(obj instanceof MyCellStyle)) {
            return false;
        }
        MyCellStyle style = (MyCellStyle) obj;
        if (this.fillPattern != null && style.fillPattern == null
                || this.fillPattern == null && style.fillPattern != null
                || this.fillPattern != null && !this.fillPattern.equals(style.fillPattern)) {
            return false;
        }
        if (this.fillBackgroundColor != null && style.fillBackgroundColor == null
                || this.fillBackgroundColor == null && style.fillBackgroundColor != null
                || this.fillBackgroundColor != null && !this.fillBackgroundColor.equals(style.fillBackgroundColor)) {
            return false;
        }
        if (this.fillForegroundColor != null && style.fillForegroundColor == null
                || this.fillForegroundColor == null && style.fillForegroundColor != null
                || this.fillForegroundColor != null && !this.fillForegroundColor.equals(style.fillForegroundColor)) {
            return false;
        }
        if (this.alignment != null && style.alignment == null
                || this.alignment == null && style.alignment != null
                || this.alignment != null && !this.alignment.equals(style.alignment)) {
            return false;
        }
        if (this.verticalAlignment != null && style.verticalAlignment == null
                || this.verticalAlignment == null && style.verticalAlignment != null
                || this.verticalAlignment != null && !this.verticalAlignment.equals(style.verticalAlignment)) {
            return false;
        }
        if (this.borderLeft != null && style.borderLeft == null
                || this.borderLeft == null && style.borderLeft != null
                || this.borderLeft != null && !this.borderLeft.equals(style.borderLeft)) {
            return false;
        }
        if (this.borderRight != null && style.borderRight == null
                || this.borderRight == null && style.borderRight != null
                || this.borderRight != null && !this.borderRight.equals(style.borderRight)) {
            return false;
        }
        if (this.borderTop != null && style.borderTop == null
                || this.borderTop == null && style.borderTop != null
                || this.borderTop != null && !this.borderTop.equals(style.borderTop)) {
            return false;
        }
        if (this.borderBottom != null && style.borderBottom == null
                || this.borderBottom == null && style.borderBottom != null
                || this.borderBottom != null && !this.borderBottom.equals(style.borderBottom)) {
            return false;
        }
        if (this.leftBorderColor != null && style.leftBorderColor == null
                || this.leftBorderColor == null && style.leftBorderColor != null
                || this.leftBorderColor != null && !this.leftBorderColor.equals(style.leftBorderColor)) {
            return false;
        }
        if (this.rightBorderColor != null && style.rightBorderColor == null
                || this.rightBorderColor == null && style.rightBorderColor != null
                || this.rightBorderColor != null && !this.rightBorderColor.equals(style.rightBorderColor)) {
            return false;
        }
        if (this.topBorderColor != null && style.topBorderColor == null
                || this.topBorderColor == null && style.topBorderColor != null
                || this.topBorderColor != null && !this.topBorderColor.equals(style.topBorderColor)) {
            return false;
        }
        if (this.bottomBorderColor != null && style.bottomBorderColor == null
                || this.bottomBorderColor == null && style.bottomBorderColor != null
                || this.bottomBorderColor != null && !this.bottomBorderColor.equals(style.bottomBorderColor)) {
            return false;
        }
        if (this.dataFormat != null && style.dataFormat == null
                || this.dataFormat == null && style.dataFormat != null
                || this.dataFormat != null && !this.dataFormat.equals(style.dataFormat)) {
            return false;
        }
        if (this.rotation != null && style.rotation == null
                || this.rotation == null && style.rotation != null
                || this.rotation != null && !this.rotation.equals(style.rotation)) {
            return false;
        }
        if (this.font != null && style.font == null
                || this.font == null && style.font != null
                || this.font != null && !this.font.equals(style.font)) {
            return false;
        }
        if (this.indention != null && style.indention == null
                || this.indention == null && style.indention != null
                || this.indention != null && !this.indention.equals(style.indention)) {
            return false;
        }
        if (this.hidden != null && style.hidden == null
                || this.hidden == null && style.hidden != null
                || this.hidden != null && !this.hidden.equals(style.hidden)) {
            return false;
        }
        if (this.locked != null && style.locked == null
                || this.locked == null && style.locked != null
                || this.locked != null && !this.locked.equals(style.locked)) {
            return false;
        }
        return (this.wrapText == null || style.wrapText != null)
                && (this.wrapText != null || style.wrapText == null)
                && (this.wrapText == null || this.wrapText.equals(style.wrapText));
    }

    public FillPatternType getFillPattern() {
        return fillPattern;
    }

    public MyCellStyle setFillPattern(FillPatternType fillPattern) {
        this.fillPattern = fillPattern;
        return this;
    }

    public Short getFillBackgroundColor() {
        return fillBackgroundColor;
    }

    public MyCellStyle setFillBackgroundColor(Short fillBackgroundColor) {
        this.fillBackgroundColor = fillBackgroundColor;
        return this;
    }

    public Short getFillForegroundColor() {
        return fillForegroundColor;
    }

    public MyCellStyle setFillForegroundColor(Short fillForegroundColor) {
        this.fillForegroundColor = fillForegroundColor;
        return this;
    }

    public HorizontalAlignment getAlignment() {
        return alignment;
    }

    public MyCellStyle setAlignment(HorizontalAlignment alignment) {
        this.alignment = alignment;
        return this;
    }

    public VerticalAlignment getVerticalAlignment() {
        return verticalAlignment;
    }

    public MyCellStyle setVerticalAlignment(VerticalAlignment verticalAlignment) {
        this.verticalAlignment = verticalAlignment;
        return this;
    }

    public BorderStyle getBorderLeft() {
        return borderLeft;
    }

    public MyCellStyle setBorderLeft(BorderStyle borderLeft) {
        this.borderLeft = borderLeft;
        return this;
    }

    public BorderStyle getBorderRight() {
        return borderRight;
    }

    public MyCellStyle setBorderRight(BorderStyle borderRight) {
        this.borderRight = borderRight;
        return this;
    }

    public BorderStyle getBorderTop() {
        return borderTop;
    }

    public MyCellStyle setBorderTop(BorderStyle borderTop) {
        this.borderTop = borderTop;
        return this;
    }

    public BorderStyle getBorderBottom() {
        return borderBottom;
    }

    public MyCellStyle setBorderBottom(BorderStyle borderBottom) {
        this.borderBottom = borderBottom;
        return this;
    }

    public Short getLeftBorderColor() {
        return leftBorderColor;
    }

    public MyCellStyle setLeftBorderColor(Short leftBorderColor) {
        this.leftBorderColor = leftBorderColor;
        return this;
    }

    public Short getRightBorderColor() {
        return rightBorderColor;
    }

    public MyCellStyle setRightBorderColor(Short rightBorderColor) {
        this.rightBorderColor = rightBorderColor;
        return this;
    }

    public Short getTopBorderColor() {
        return topBorderColor;
    }

    public MyCellStyle setTopBorderColor(Short topBorderColor) {
        this.topBorderColor = topBorderColor;
        return this;
    }

    public Short getBottomBorderColor() {
        return bottomBorderColor;
    }

    public MyCellStyle setBottomBorderColor(Short bottomBorderColor) {
        this.bottomBorderColor = bottomBorderColor;
        return this;
    }

    public Short getDataFormat() {
        return dataFormat;
    }

    public MyCellStyle setDataFormat(Short dataFormat) {
        this.dataFormat = dataFormat;
        return this;
    }

    public Short getRotation() {
        return rotation;
    }

    public MyCellStyle setRotation(Short rotation) {
        this.rotation = rotation;
        return this;
    }

    public MyFont getFont() {
        return font;
    }

    public MyCellStyle setFont(MyFont font) {
        if (font != null && this.font != null) {
            this.font.merge(font);
        } else {
            this.font = font;
        }
        return this;
    }

    public Short getIndention() {
        return indention;
    }

    public MyCellStyle setIndention(Short indention) {
        this.indention = indention;
        return this;
    }

    public Boolean getHidden() {
        return hidden;
    }

    public MyCellStyle setHidden(Boolean hidden) {
        this.hidden = hidden;
        return this;
    }

    public Boolean getLocked() {
        return locked;
    }

    public MyCellStyle setLocked(Boolean locked) {
        this.locked = locked;
        return this;
    }

    public Boolean getWrapText() {
        return wrapText;
    }

    public MyCellStyle setWrapText(Boolean wrapText) {
        this.wrapText = wrapText;
        return this;
    }
}
